package com.lxq.live.pojo;

import java.util.Calendar;

public class VerificationCode {
    private String userId;
    private int leftOvers;
    private String latestCode;
    private long latestCodeExpired;
    private final long transactionExpired;
    private boolean valid;

    public VerificationCode() {
        var calendar = Calendar.getInstance();
        calendar.add(Calendar.HOUR_OF_DAY,24);
        this.transactionExpired= calendar.getTime().getTime();
        this.leftOvers=3;
        this.valid=true;
    }

    public void leftOversDown(){
        this.leftOvers--;
    }

    public void setValid(boolean valid) {
        this.valid = valid;
    }

    public boolean isValid() {
        return valid;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public int getLeftOvers() {
        return leftOvers;
    }

    public void setLeftOvers(int leftOvers) {
        this.leftOvers = leftOvers;
    }

    public String getLatestCode() {
        return latestCode;
    }

    public void setLatestCode(String latestCode) {
        var calendar = Calendar.getInstance();
        calendar.add(Calendar.MINUTE,10);
        this.setLatestCodeExpired(calendar.getTime().getTime());
        this.latestCode = latestCode;
    }

    public long getLatestCodeExpired() {
        return latestCodeExpired;
    }

    public void setLatestCodeExpired(long latestCodeExpired) {
        this.latestCodeExpired = latestCodeExpired;
    }

    public long getTransactionExpired() {
        return transactionExpired;
    }

    @Override
    public String toString() {
        return "VerificationCode{" +
                "userId='" + userId + '\'' +
                ", leftOvers=" + leftOvers +
                ", latestCode='" + latestCode + '\'' +
                ", lateCodeExpired=" + latestCodeExpired +
                ", transactionExpired=" + transactionExpired +
                '}';
    }
}
